import libtcodpy as libtcod
import config


import bodysim, events, items, ent

PLAYER_DEBUG = False

if config.__PYSKILLER_DEBUG:
	PLAYER_DEBUG = True
	
class PlayerEnt(ent.Human):
	def __init__(self, em, x, y, char, color):
		super(PlayerEnt,self).__init__(em, x, y, char, color)
		
		self.chunk_x = 0
		self.chunk_y = 0
		
		
		self.fow_outdated = True
		self.hp = 10
		self.name = "player"
		self.model = "@"
		
		self.set_container(ent.NPCContainer())
		
		#some debug shit
		knife = items.Item("Knife")
		
		if PLAYER_DEBUG:
			knife.effects["damage"] = 3
		else:
			knife.effects["damage"] = 3
			
		knife.effects["damage_type"] = "dmg_cut"
		knife.slot = "weapon"
		knife.pick_up(self)
		
		self.container.equip(knife) 	#by default
		
		hammer = items.Item("Hammer")
		hammer.effects["damage"] = 5
		hammer.effects["damage_type"] = "dmg_blunt"
		hammer.effects["stun_chance"] = 15		#+30% of stun
		hammer.slot = "weapon"
		hammer.pick_up(self)
		
		#self.container.append(items.Item("Knife"))
		#self.container.append(items.Item("Hammer"))
		
		#this is a simple hack
		#todo: probably implement a fluid system
		#todo: add water source
		#todo: add 'cleanup' command (only on water source)
		self.bloody = False
	 	
	def move(self, dx, dy):
		if self.em.map.get_obstacle(self.x+dx, self.y+dy):
			self.attack(self.x+dx, self.y+dy)
		else:
			super(PlayerEnt,self).move(dx,dy)
			
				
	
	def die(self, killer = None):
		super(PlayerEnt,self).die(killer)
		self.em.services["render"].message("You have died!",libtcod.red);
		
		
	def get_fov_radius(self):
		return self.combat.get_fov()
		
	def notify(self, event):
		if isinstance(event,events.MurderEvent):
			if event.criminal == self:
				#bad (good?) news, we killed someone
				self.color = libtcod.dark_red
				self.bloody = True
				
	def on_move(self,x,y):
		for item_ent in self.tile.objects:
			if isinstance(item_ent, ent.ItemEntity):
				item_ent.pick_up(self)
				item_ent.destroy()
				
				
		self.fow_outdated = True
		self.em.viewport.locate(self.x,self.y)		
		
